package com.bkhc.product.repository;

import com.bkhc.product.entity.SpecRange;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SpecRangeRepository extends JpaRepository<SpecRange,String> , JpaSpecificationExecutor<SpecRange> {
    SpecRange findByRangeValueAndSpecCode(String rangeValue,String specCode);
    List<SpecRange> findBySpecCode(String specCode);
    void deleteByRangeCode(String rangeCode);
    void deleteBySpecCode(String specCode);

    SpecRange findByRangeCode(String rangeCode);
    @Query("delete from SpecRange s where s.specCode in (select c.specCode from Spec c where c.productCode= :productCode)")
    @Modifying
    void deleteByProductCode(@Param("productCode")String productCode);
    @Query("select s from SpecRange s WHERE s.specCode in (:specCodes) order by s.sort")
    List<SpecRange> findInSpecCodeList(@Param("specCodes") List<String> specCodes);

    void deleteBySpecCodeIn(List<String> specCodeList);
}
